#!/bin/sh
# Xsuwaveform2 - Demo shell script for program SUWAVEFORM
# Author: Nils Maercklin, 2006
#
# This demo shell script shows the generation of Berlage wavelets
# with different time exponent tn or decay factor (X window plots).

# Set constant waveform parameters:
ns=101     # trace length in samples
dt=0.004   # time sampling rate in seconds
fpeak=20   # peak frequency
cdecay=80  # constant exponential decay factor (berlage_wavelet1.su)
ctn=2      # constant time exponent  (berlage_wavelet2.su)


# X window sizes and positions:
WIDTH=500
HEIGHT=700
WIDTHOFF1=50
WIDTHOFF2=600
HEIGHTOFF=50


# Create empty wavelet output files:
> berlage_wavelet1.su
> berlage_wavelet2.su

# Generate Berlage wavelets with different time exponent tn,
# normalize by maximum amplitude, and store tn in header 
# otrav for plotting:
for tn in 0 1 2 3 4 5
do
    # Berlage wavelet:
    suwaveform type=berlage fpeak=$fpeak tn=$tn decay=$cdecay \
        ns=$ns dt=$dt \
    | sushw key=otrav a=$tn \
    | sugain qbal=1 >> berlage_wavelet1.su
done

# Generate Berlage wavelets with different time exponent tn,
# normalize by maximum amplitude, and store decay in header 
# otrav for plotting:
for decay in 20 40 60 80 100 120
do
    # Berlage wavelet:
    suwaveform type=berlage fpeak=$fpeak tn=$ctn decay=$decay \
        ns=$ns dt=$dt \
    | sushw key=otrav a=$decay \
    | sugain qbal=1 >> berlage_wavelet2.su
done


# X window plot of Berlage wavelets with different tn:
suxwigb <berlage_wavelet1.su key=otrav windowtitle="Berlage wavelets" \
    title="wavelet type=berlage fpeak=$fpeak decay=$cdecay" grid1=dot \
    xcur=0.75 label1=" time (s)" label2="time exponent tn" \
    wbox=$WIDTH hbox=$HEIGHT xbox=$WIDTHOFF1 ybox=$HEIGHTOFF &

# X window plot of Berlage wavelets with different decay:
suxwigb <berlage_wavelet2.su key=otrav windowtitle="Berlage wavelets" \
    title="wavelet type=berlage fpeak=$fpeak tn=$ctn" grid1=dot \
    xcur=0.75 label1=" time (s)" label2="exponential decay factor" \
    wbox=$WIDTH hbox=$HEIGHT xbox=$WIDTHOFF2 ybox=$HEIGHTOFF &


# User info:
cat <<EOF >> /dev/stderr
 Files created by demo Xsuwaveform2:

 berlage_wavelet1.su   data file 1, Berlage wavelets with different tn
 berlage_wavelet2.su   data file 2, Berlage wavelets with different decay

EOF

exit 0
